<?php
/*************************************************

点赞公共控制器 - the 
Author: WangHuabin <17-5-27>

*************************************************/
namespace Home\Controller;
use Think\Controller;
class PraiseController extends Controller {

    public function ajax_praise(){
        $type = I('post.type');
    //    print_r($type);die;
        $id = I('post.id');

        $z_type  = 6;
        if($type==1){
            $house_id = I('post.house_id');
        }else if($type==2){
            $house_id = I('post.video_id');
        }else if($type==3){
            $house_id = I('post.video_id');
            $map['id'] = $house_id;
            $info = D('Comment')->get_one($map);
            $send_id = $info['user_id'];
        }else if($type==5){
            $house_id = I('post.answer_id');
        }else if($type==6){
            $house_id = I('post.commentid');
            $map['id'] = $house_id;
            $info = D('PlatformCommentary')->get_one($map);
            $send_id = $info['user_id'];
            $z_type=17;
        }else if($type==7){
            $house_id = I('post.depthid');
            $map['id'] = $house_id;
            $info = D('Depth')->get_one($map);
            $send_id = $info['user_id'];
            $z_type=14;
        }else if($type==8){
            $house_id = I('post.opinionid');
            $map['id'] = $house_id;
            $info = D('CircleOpinion')->get_one($map);
            $send_id = $info['user_id'];
            $z_type=15;
        }else if($type==9){
            $house_id = I('post.announceid');
            $map['id'] = $house_id;
            $info = D('CircleAnnounce')->get_one($map);
            $send_id = $info['user_id'];
            $z_type=16;
        }else{
            $house_id = I('post.id');
        }
        $user_id = $_SESSION['user']['id'];
        if($user_id){
            $map = array();
            $map['id_user'] = $user_id;
            $map['id_target'] =$id;
            if($type){
                $map['type'] =$type;
            }
            $praise = D('Praise')->get_one($map);
           
            if($praise){
                $this->ajaxReturn(array('err'=>1,"msg"=>"您已经点过赞了！"));
            }else{
                 $res = praise_push_count($type,$house_id);
                //print_r($res);die;
                if($res){
                    $data['id_user'] = $user_id;
                    $data['id_target'] =$id;
                    $data['add_time'] =time();
                    $data['type'] =$type;
                    $r = D('Praise')->add($data);
                }
                R('Msg/sendmail',array('typename'=>'praise','userid'=>$send_id,'val'=>1,'type'=>$z_type,'t_id'=>$id,'t_user_id'=>$user_id,'content'=>0));

                $this->ajaxReturn(array('err'=>0));
            }
        }else{
            $this->ajaxReturn(array('err'=>2,"msg"=>"请先登录"));
        }
        
    }

}